-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding the Program.cs file to each module was the issue. #10
Adding the Program.cs file to each module was the issue. #10
Conversation
Hi, Thanks for contribution :) My goal is having 1 API Layer. And each module have own separate Program.cs. and with this approach each module with using Program.cs can host itself and we don't need to have separate API layer for each module and we need 1 API layer for coordination all of the module and having multiple API leads us to having separated microservices not modular monolith. |
I deleted the extra API layer that I had added to each module before, and I added a Program.cs to each module (related class library). Now, each module can be hosted and executed independently. However, I don't fully understand why we should add Program.cs to a class library (each module) if it cannot be hosted and run on its own. Wouldn't it be more efficient to keep an extra layer, such as a console application or API, that can be executed or hosted directly and reference the related class library? Am I right or wrong in my understanding? |
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<OutputType>Exe</OutputType> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove OutputType tag, it's not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove OutputType tag, it's not necessary.
I applied the changes and I used top level statement like Api layer for program.cs but
for top-level statements in C# to work, the project must be configured as an executable. By removing this tag, the project will default to a class library, which does not support top-level statements.
The tag specifies whether the project is a library or an executable.
With the set to Exe, our top-level statements in Program.cs will work as intended.
Should I remove the tag or leave it as is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here in Api layer we don't have any additional configuration and it can host as well. also you need to add Properties folder and add configuration json file for host like Api layer. You need the follow the configuration exactly like Api layer and also add Properties folder and afterward each module should host properly, Also you need to change project structure to Microsoft.NET.Sdk.Web
:
Api.csproj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed your instructions and added a Properties folder with a configuration JSON file to each module, similar to the API layer. I also changed the project structure to Microsoft.NET.Sdk.Web. However, I'm not sure if everything is correct?
for launchSetting i changed the port for each module. should all ports be exactly the same as api layer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed your instructions and added a Properties folder with a configuration JSON file to each module, similar to the API layer. I also changed the project structure to Microsoft.NET.Sdk.Web. However, I'm not sure if everything is correct? for launchSetting i changed the port for each module. should all ports be exactly the same as api layer?
Thanks. Port should be different for each module. everything's seems good.
If we have a separate Api for each module it provides complexity and we don't need it and we just need a simple Program.cs class for running independently each module. (it's also not very force, but it easier to have each module rune separately. But in the end modular monolith we have to one deployment). |
/add launchSetting.json to each module and Updated ports /change modules Sdk to "Microsoft.NET.Sdk.Web" /remove unnecessary tags in .csproj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contribution :)
Title: Added Extra API Layer for Better Organization
issue: #2
Description:
Added Program.cs to each module and implemented an extra API layer for better organization and maintainability. Also we could have achieved this with a single API layer, but this approach provides a clearer separation of concerns and easier integration with related libraries. I'm open to feedback and discussion on this change, and would appreciate any suggestions on how to improve the design.